package com.dao.hibernateAndJdbc;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;

import com.order.target.TestOrderTarget;

public class TestByXml {
	
	private static String configPath = "applicationContext.xml";
	private static ApplicationContext applicationContext = new ClassPathXmlApplicationContext(configPath);;
	
	public static void main(String[] args) {
		    UserService service = (UserService) applicationContext.getBean("userService");
	        JdbcTemplate jdbcTemplate = (JdbcTemplate) applicationContext.getBean("jdbcTemplate");
	        //插入一条记录，初始分数为10
	        jdbcTemplate.execute("INSERT INTO t_user(user_name,password,score,last_logon_time) VALUES('tom','123456',10,"+System.currentTimeMillis()+")");

	        //调用工作在无事务环境下的服务类方法,将分数添加20分
	        System.out.println("before userService.logon()..");
	        service.logon("tom");
	        System.out.println("after userService.logon()..");
	         
	        int score = jdbcTemplate.queryForInt("SELECT score FROM t_user WHERE user_name ='tom'");
	        System.out.println("score:"+score);
	        jdbcTemplate.execute("DELETE FROM t_user WHERE user_name='tom'");
	}
}
